<?	
class NewsCommon
{	
	private $project;
	private $db_name;
	
	private function setProjectId($id=1)
	{		 
		$this->project = $id*1;		
	}
	
	private function getProjectId()
	{
		return $this->project;
	}
	
	public function setDbName($db='news_common')
	{
		$this->db_name = $db;		
	}
	
	private function getDbName()
	{
		return $this->db_name;
	}
		
	function __construct($project_id=5, $db='news_common')
	{
		$this->setProjectId($project_id);
		$this->setDbName($db);
	}
	
	
	function getYesterdayMostCommented($args)
	{
		$news_manager = new NewsCommonManager();
		$result = $news_manager->getYesterdayMostCommentedNewsId($this->getProjectId(),$this->getDbName(),&$args);
		$news_list = $news_manager->getNewsListExtended($result['data'],$this->getProjectId(),$this->getDbName());
		
		return array('news_data' => $result, 'news_list' => $news_list);
	}
	
	
	function addCommonReiting($news_id, $bal)
	{
		$news_manager = new NewsCommonManager();
		$news_manager->addCommonReiting($news_id, $bal, $this->getDbName(), $this->getProjectId());
	}
	
	function getStatisticByNewsList($id_array)
	{		
		$news_manager = new NewsCommonManager();
		return $news_manager->getStatisticByNewsList($this->getProjectId(), $this->getDbName(), $id_array);		
	}
	
	function getAuthorByCityId($city_id)
	{
		$news_manager = new NewsCommonManager();
		return $news_manager->getAuthorByCityId($city_id, $this->getDbName(), $this->getProjectId());
	}
	
	function getNewsListByTagId($tag_id, $args)
	{
		$tags_manager = new TagsCommonManager();
		
		$result = $tags_manager->getNewsListIdByTagId($tag_id, &$args, $this->getProjectId(), $this->getDbName());
		
		$news_manager = new NewsCommonManager();		
		$data = $news_manager->getNewsListExtended($result['data'],$this->getProjectId(),$this->getDbName());
		
		return array('count' => $result['count'], 'data' => $data);
	}
	
	function getRubricsList()
	{
		$news_manager = new NewsCommonManager();
		return $news_manager->getRubricsList($this->getProjectId(),$this->getDbName());
	}
	
	
	function getRubricById($rubric_id)
	{
		$news_manager = new NewsCommonManager();
		return $news_manager->getRubricById($this->getProjectId(),$this->getDbName(),$rubric_id);
	}
	
	function getMostCommentNews($arg=array(), $count_days=7)
	{
		$news_manager = new NewsCommonManager();
		return $news_manager->getMostCommentNews($this->getProjectId(), $this->getDbName(), &$arg, $count_days);
	}
	
	function getMostViewNews($arg=array(), $count_days=7)
	{
		$news_manager = new NewsCommonManager();
		return $news_manager->getMostViewNews($this->getProjectId(), $this->getDbName(), &$arg, $count_days);
	}
	
	function getTopNews($news_type_id, $limit, $arg = array())
	{
		$news_manager = new NewsCommonManager();
		$id = $news_manager->getTopNews($news_type_id, $limit, &$arg, $this->getProjectId(), $this->getDbName());
		
		return $news_manager->getNewsListExtended(&$id, $this->getProjectId(), $this->getDbName());
	}
	
	function getNewsList($arg = array())
	{
		
		/*foreach ($arg as $key => $value)
		{
			if ($key)
			{
				$this->$key = $value;
			}
		}*/
		
		$this->project_id = $this->getProjectId();		
		$this->project_db = $this->getDbName();
		
		$newsCommonManager = new NewsCommonManager();
		
		$result = $newsCommonManager->getNewsList($this, &$arg);
		
		return $result;		
	}

	function getNewsListByIdList($id_array)
	{
		$newsCommonManager = new NewsCommonManager();
		return $newsCommonManager->getNewsListByIdList($id_array, $this->getProjectId(), $this->getDbName());		
	}
	
	function getNewsListExtended($arg = array())
	{		
		$this->project_id = $this->getProjectId();		
		$this->project_db = $this->getDbName();
		
		$newsCommonManager = new NewsCommonManager();
		
		$id_array = $newsCommonManager->getNewsListId($this, &$arg);	
			
		$result = $newsCommonManager->getNewsListExtended(&$id_array['data'], $this->getProjectId(), $this->getDbName());
		
		return array('count' => $id_array['count'], 'data' => $result);		
	}
	
	function getNewsListExtendedByIdList($id_array = array())
	{		
		$this->project_id = $this->getProjectId();		
		$this->project_db = $this->getDbName();
		
		$newsCommonManager = new NewsCommonManager();
		
		return $newsCommonManager->getNewsListExtended(&$id_array, $this->getProjectId(), $this->getDbName());		
	}	
	
	function getNewsById($news_id)
	{
		$this->project_id = $this->getProjectId();		
		$this->project_db = $this->getDbName();
					
		$newsCommonManager = new NewsCommonManager();		
		$newsCommonManager->updateViewCountForNews($news_id, $this->getDbName());
		return $newsCommonManager->getNewsById($news_id, $this->getProjectId(), $this->getDbName());		 
	}
	
}
?>